//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//===============================================================================
// Copyright � Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;

using MVPComposibility.ContactManager.Views.ContactDetails;
using MVPComposibility.ContactManager.Views.ContactList;

namespace MVPComposibility.ContactManager.Views
{
	public class ListDetailsMediator
	{
		private ContactDetailsModel _detailsModel;
		private IContactListModel _listModel;

		public ContactDetailsModel DetailsModel
		{
			get { return _detailsModel; }
			set { _detailsModel = value; }
		}

		public IContactListModel ListModel
		{
			get { return _listModel; }
			set { _listModel = value; }
		}

		public void Initialize()
		{
		}

		public void Load()
		{
			ListModel.SelectedContactChanged += ListModel_SelectedContactChanged;
			ListModel.Initialized += ListModel_Initialized;
			DetailsModel.EditCompleted += DetailsModel_EditCompleted;
		}

		void ListModel_Initialized(object sender, EventArgs e)
		{
			DetailsModel.RestoreContactFromPersistentState(ListModel.SelectedContact);
		}

		void DetailsModel_EditCompleted(object sender, EventArgs e)
		{
			ListModel.ContentChange();
		}

		void ListModel_SelectedContactChanged(object sender, EventArgs e)
		{
			DetailsModel.Contact = ListModel.SelectedContact;
		}
	}
}
